<body class="wy-body">
<div class="layui-fluid">
	<div class="layui-card">
		<div class="layui-form layui-card-header wy-card-header-auto">
			<div class="layui-form-item">
			<form action="{:url(request()->action())}" method="get">
				<input name="table_id" type="hidden" value="{$get_data.table_id}">
				{volist name="$table_info.nav" id="vo"}
{switch $vo.type}
    {case radio|select|checkbox}
		<div class="layui-inline ajax_select_config" name="{$vo.field_name}" field_type="{$vo.type}" attr_type="{$vo.attr_type}" val="{$get_data[$vo['field_name']]}">
			<label class="layui-form-label wy-width-auto">{$vo.cname}</label>
		</div>
	{/case}
    {default /}
		<div class="layui-inline">
			<label class="layui-form-label wy-width-auto">{$vo.cname}</label>
			<div class="layui-input-inline">
				<input type="text" name="{$vo.field_name}" placeholder="请输入{$vo.cname}" autocomplete="off" class="layui-input" value="{$get_data[$vo['field_name']]}">
			</div>
		</div>
{/switch}
				{/volist}

				<div class="layui-inline">
					<label class="layui-form-label wy-width-auto">栏目</label>
					<div class="layui-input-inline">
						<select name="cid">
							<option value="">--请选择--</option>
							{volist name="cat_lists" id="vo"}
							<option value="{$vo.id}" {if $get_data.cid == $vo.id} selected {/if} {if $get_data.table_id != $vo.table_id} disabled {/if}>{$vo.name|raw}</option>
							{/volist}
						</select>
					</div>
				</div>
				<div class="layui-inline">
					<label class="layui-form-label wy-width-auto">发布时间</label>
					<div class="layui-input-inline">
						<input type="text" name="push" class="layui-input wy-datetime-range" placeholder=" ~ " value="{$get_data.push}">
					</div>
				</div>
				<div class="layui-inline">
					<label class="layui-form-label wy-width-auto">状态</label>
					<div class="layui-input-inline">
						<select name="status">
							<option value="">--请选择--</option>
							<option value="1" {if $get_data.status == 1} selected {/if}>展示中</option>
							<option value="2" {if $get_data.status == 2} selected {/if}>未开始</option>
							<option value="3" {if $get_data.status == 3} selected {/if}>已结束</option>
							<option value="4" {if $get_data.status == 4} selected {/if}>已关闭</option>
						</select>
					</div>
				</div>
				<div class="layui-inline">
					<button class="layui-btn">
						<i class="layui-icon layui-icon-search"></i>
					</button>
				</div>
			</form>
			</div>
		</div>

		<div class="layui-card-body">
			<div style="padding-bottom: 10px;">
				<button class="layui-btn wy_but"
					wy-event="lay_ajax_post"
					wy-url="{:url('lists_del')}?table_id={$get_data['table_id']}"
					wy-tips="确认是否删除该信息，删除以后将无法恢复"
					wy-table="wy_table_lists"
					wy-field="id"
				>删除</button>
				<button class="layui-btn wy_but"
					wy-event="lay_top_ifram"
					wy-url="{:url('lists_add')}?table_id={$get_data['table_id']}&cat_id={$get_data['cid']}"
					wy-title="添加"
				>添加</button>
			</div>

<table class="layui-table" name="wy_table_lists" lay-filter="wy_table_lists"
	lay-data="{
		height:'full-166',
		cellMinWidth:'180',
		url:'{:url('ajax_lists')}',
		where: {
			{$get_str}
		},
		method:'post',
		page:true,
		id:'wy_table_lists',
		limit:15,
		limits:[15,30,50,100]}"
>
<thead>
<thead>
<tr>
	<th lay-data="{type: 'checkbox'}">选择</th>
	<th lay-data="{width:'80',field:'id'}">ID</th>

	{volist name="$table_info.nav" id="vo"}
	<th lay-data="{field:'{$vo.field_name}'}">{$vo.cname}</th>
	{/volist}

	<th lay-data="{field:'cat_name'}">栏目</th>
	<th lay-data="{width:'80',field:'onclick'}">访问量</th>
	<th lay-data="{width:'80',field:'sort'}">排序</th>
	<th lay-data="{width:'100',templet:'#statusTool'}">状态</th>
	<th lay-data="{field:'push_date'}">开始时间</th>
	<th lay-data="{field:'create_date'}">发布时间</th>
	<th lay-data="{width:'120',toolbar:'#barTool'}">操作</th>
</tr>
</thead>
</table>
<script type="text/html" id="statusTool">
{{# if(d.status == 1){ }}
	<span class="layui-btn layui-btn-xs layui-btn-danger">启用</span>
{{# }else{ }}
	<span class="layui-btn layui-btn-xs layui-btn-disabled">禁用</span>
{{# } }}
</script>
<script type="text/html" id="barTool">
<div class="layui-btn-group">
	<a class="layui-btn layui-btn-xs layui-btn-primary wy_but"
		wy-event="lay_top_ifram"
		wy-url="{:url('lists_edit')}?table_id={$get_data['table_id']}&id={{d.id}}&cat_id={$get_data['cid']}"
		wy-title="编辑"
	>编辑</a>

	<a class="layui-btn layui-btn-xs layui-btn-primary wy_but"
		wy-event="lay_ajax_get"
		wy-url="{:url('lists_del')}?table_id={$get_data['table_id']}&id={{d.id}}"
		wy-tips="确认是否删除该信息，删除以后将无法恢复"
		wy-table="wy_table_lists"
	>删除</a>
	
</div>
</script>

		</div>
	</div>
</div>
<style>
.wy-btn-select{
	width:auto;
}
</style>
<script>
layui.define(['form'], function(exports) {
    var $		= layui.jquery,
		layer	= layui.layer,
		form	= layui.form;
	$('.ajax_select_config').each(function(){

		var _this = $(this);
		var name = _this.attr('name');
		var field_type = _this.attr('field_type');
		var attr_type = _this.attr('attr_type');
		var val = _this.attr('val');

		$.post("{:url('Contentajax/ajax_select_config')}",{field_type:field_type,attr_type:attr_type,val:val},function(data){
			if(data.code != 1){
				layer.msg(data.msg,{icon:0});
				return false;
			}
			if(data.data){
				var _html = '';
				var data_class_id = name+'-';
				if(attr_type == 'config_area'){
					var config_area = data.data;

					$.each(config_area,function(m,n){
						if(n.length > 0){
							data_class_id += m+'-'
							_html += '<div class="layui-input-inline">';
							_html += '<select name="'+name+'-'+m+'" lay-filter="config_area" attr_class="'+data_class_id+'" attr_num="'+m+'" attr_name="'+name+'">';
							_html += '<option value="">--请选择--</option>';
							for(i = 0 ; i < n.length ; i++){
								var is_selected = '';
								if(n[i]['selected'] == 1){
									is_selected = ' selected ';
								}
								_html += '<option value="'+n[i]['id']+'" '+is_selected+'>'+n[i]['name']+'</option>';
							}
							_html += '</select>';
							_html += '</div>';
						}
					});
				}else{
					if(data.data.length == 0){
						return false;
					}
					var _html = '<div class="layui-input-inline">';
						_html += '<select name="'+name+'" lay-filter="'+attr_type+'" >';
						_html += '<option value="">--请选择--</option>';
					var config_area = data.data;
					$.each(config_area,function(m,n){
						var is_selected = '';
						if(n['selected'] == 1){
							is_selected = ' selected ';
						}
						_html += '<option value="'+n['id']+'" '+is_selected+'>'+n['name']+'</option>';
					});
					_html += '</select>';
					_html += '</div>';

				}

				_this.append(_html);
				form.render('select');
			}else{
				_this.remove();
			}




		},"JSON");
	});

	form.on('select(config_area)', function(data){

		var attr_class = data.elem.getAttribute('attr_class');
		var attr_num = data.elem.getAttribute('attr_num');
		var attr_name = data.elem.getAttribute('attr_name');
		$(document).find("select[attr_class^='"+attr_class+"']").each(function(){
			console.log($(this))
			var _this_p_idv = $(this).attr("attr_class");
			if(_this_p_idv != attr_class){
			   $(this).parent().remove();
			}
		});
		$.post("{:url('Contentajax/ajax_config_area')}",{area_id:data.value},function(data){
			if(data.code != 1){
				layer.msg(data.msg,{icon:0});
				return false;
			}
			if(data.data.length == 0){
				return false;
			}
			attr_num++;
			data_class_id = name+'-';
			var _html = '<div class="layui-input-inline">';
				_html += '<select name="'+attr_name+'-'+attr_num+'" lay-filter="config_area" attr_class="'+attr_class+''+attr_num+'-" attr_num="'+attr_num+'" attr_name="'+attr_name+'">';
				_html += '<option value="">--请选择--</option>';
			var config_area = data.data;
			$.each(config_area,function(m,n){
				_html += '<option value="'+config_area[m]['id']+'" >'+config_area[m]['name']+'</option>';
			});
			_html += '</select>';
			_html += '</div>';

			$(".ajax_select_config[name='"+attr_name+"']").append(_html);
			form.render('select');
		},"JSON");
		//
	});
})
</script>
</body>